package com.vlong.town.controller.client.suggestion;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.vlong.town.controller.base.BaseController;
import com.vlong.town.entity.base.DataMessage;
import com.vlong.town.entity.wxUser.WxUser;
/**
 * 村委信箱控制器
 * @author 51088
 */
import com.vlong.town.service.suggestion.SuggestionService;
import com.vlong.town.service.wxUser.WxUserService;
import com.vlong.town.util.common.TownConstant;
@Controller
@RequestMapping("/client/suggestion")
public class SuggestionClientController extends BaseController{
	
	@Autowired
	private SuggestionService suggestionService;//村委信箱业务接口
	
	@Autowired
	private  WxUserService  wxUserService;
	
	/**
	 * 跳转村委信箱页面
	 * @return
	 */
	@RequestMapping("/list")
	public String list(){
		//获取SESSION信息
		String telphone = getTelphone();
		request.setAttribute("telphone", telphone);
		return "client/suggestion/form_suggestion";
	}
	
	
	
	/**
	 * 添加反馈信息
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/addSuggestion")
	public DataMessage addSuggestion(
			@RequestParam(required=false, value="title") String title,
            @RequestParam(required=false, value="content") String content,
            @RequestParam(required=false, value="publishUserName") String publishUserName,
            @RequestParam(required=false, value="email") String email
			){
		DataMessage  dm=new DataMessage();
		if(!validateStringProperty(title, 3, 15)){
			dm.setResult(TownConstant.RESULT_CODE_DATA_ERROR);
			dm.setMessage("标题参数错误");
		}else if(!validateStringProperty(publishUserName, 2, 8)){
			dm.setResult(TownConstant.RESULT_CODE_DATA_ERROR);
			dm.setMessage("名字参数错误");
		}else{
			String telphone = getTelphone();
			List<WxUser> queryList = wxUserService.queryList(null, 1, null, null, null, null, null, null, null, null, null, telphone.trim(), null, null, null, null, null);
			WxUser wxUser = queryList.get(0);
			this.suggestionService.add(null, 1, title, null, content, wxUser.getUserId(), publishUserName, telphone, email, null, null, null, null, null, System.currentTimeMillis(), null);
			dm.setResult(TownConstant.RESULT_CODE_SUCCESS);
		}
		return dm;
	}
	
	
	
	
	
	

}
